﻿'use strict';

var app = angular.module('GridApp', ['ngGrid', 'ui.bootstrap', 'ngResource']);

//example of using .value service,  these should probably go in  a factory instead,
//they shouldn't be in the global namespace which is where they were.

app.value('SPHandy', {
    context: SP.ClientContext.get_current(),
    user:SP.ClientContext.get_current().get_web().get_currentUser(),
    getQueryStringParameter: function (paramToRetrieve) {
        var params =
        document.URL.split("?")[1].split("&");
        var strParams = "";
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split("=");
            if (singleParam[0] == paramToRetrieve)
                return singleParam[1];
        }
    },
    getZRows: function (rXML) {
        //Shamelessly stolen from SPServices, cheers Marc
        //SPServices.codeplex.com/
        var rows;

        var itemCount = $(rXML).find("rs\\:data").attr("ItemCount");
        if (rXML.getElementsByTagName("z:row").length == 0 && itemCount == undefined) {
            rows = rXML.getElementsByTagNameNS("*", "row");
        }
        else {
            rows = rXML.getElementsByTagName("z:row");
        }

        return $(rows);
    }
});
